<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>woodwhales-code-generator</title>
    <link rel="stylesheet" th:href="@{/webjars/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/code-generator/my-css/mycss.css}">
    <style>
        .layui-table-cell {
            height:auto;
        }
    </style>
</head>
<body>
    <div class="layui-container">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
            <legend>选择配置</legend>
        </fieldset>

        <table id="dbConfigTable" lay-filter="dbConfigTable"></table>
    </div>

    <script type="text/html" id="confirmDbConfig">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-xs" lay-event="getCheckData">确认配置</button>
        </div>
    </script>

    <script type="text/html" id="dbConfigTpl" th:inline="none">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">ip：</label>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux">{{d.configIp}}</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">port：</label>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux">{{d.configPort}}</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">username：</label>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux">{{d.configUsername}}</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">sid：</label>
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux">{{d.configSid}}</div>
                </div>
            </div>
        </form>
    </script>

    <script th:src="@{/webjars/layui/layui.js}"></script>
    <script th:src="@{/webjars/jquery/jquery.min.js}"></script>
    <script type="text/javascript" th:inline="none">
        layui.use(['form', 'layer', 'table', 'layedit', 'util', 'element'], function(){
            var form = layui.form,
                table = layui.table,
                layer = layui.layer;

            table.render({
                elem: '#dbConfigTable'
                ,url: '/databaseConfig/page'
                ,toolbar: '#confirmDbConfig'
                ,page: true
                ,cols: [[
                    {field: 'configCode', title: '编号', width:'10%', templet: function(d){
                        return d.configCode.substring(d.configCode.length-6);
                    }}
                    ,{field: 'configName', title: '配置名称', width:'35%',}
                    ,{title: '配置', width:'35%', templet: '#dbConfigTpl'}
                    ,{field: 'gmtModified', title: '更新时间', width:'20%'}
                ]]
            });

            table.on('row(dbConfigTable)', function(obj){
                window.parent.loadDbConfig(obj.data.configCode);
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });

        });
    </script>
</body>
</html>